Conditions | 6 |
Paths | 75 |
Total Lines | 59 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var whois = require('../common/whoiswrapper.js'), |
||
18 | ipcRenderer.on('sw:results', function(event, domainResults) { |
||
19 | const { |
||
20 | isDomainAvailable |
||
21 | } = whois; |
||
22 | var domainStatus, domainResultsJSON; |
||
23 | //ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults)); |
||
24 | |||
25 | domainResultsJSON = (function() { |
||
26 | var result; |
||
27 | if (typeof domainResults === 'object') { |
||
28 | JSON.stringify(domainResults, null, 2); |
||
29 | result = domainResults.map(function(data) { |
||
30 | data.data = parseRawData(data.data); |
||
31 | return data; |
||
32 | }); |
||
33 | } else { |
||
34 | result = parseRawData(domainResults); |
||
35 | } |
||
36 | return result; |
||
37 | })(); |
||
38 | |||
39 | // Check domain status |
||
40 | domainStatus = isDomainAvailable(domainResults); |
||
41 | |||
42 | switch (domainStatus) { |
||
43 | case 'querylimituniregistry': |
||
44 | case 'error': |
||
45 | $('#swMessageWhoisResults').text("Whois error: {0}\n{1}".format(domainStatus, domainResults)); |
||
46 | $('#swMessageError').removeClass('is-hidden'); |
||
47 | break; |
||
48 | case 'unavailable': |
||
49 | //console.log(domainResultsJSON); |
||
50 | $('#swMessageUnavailable').removeClass('is-hidden'); |
||
51 | $('#swMessageWhoisResults').text(domainResults); |
||
52 | |||
53 | $('#swTdDomain').attr('href', "http://" + domainResultsJSON['domainName'] || domainResultsJSON['domain']); |
||
54 | $('#swTdDomain').text(domainResultsJSON['domainName'] || domainResultsJSON['domain']); |
||
55 | |||
56 | $('#swTdUpdate').text(domainResultsJSON['updatedDate']); |
||
57 | $('#swTdRegistrar').text(domainResultsJSON['registrar']); |
||
58 | $('#swTdCreation').text(domainResultsJSON['creationDate'] || domainResultsJSON['createdDate'] || domainResultsJSON['created']); |
||
59 | $('#swTdCompany').text(domainResultsJSON['registrantOrganization'] || domainResultsJSON['registrant']); |
||
60 | $('#swTdExpiry').text(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['Registry Expiry Date']); |
||
61 | $('#swTableWhoisinfo.is-hidden').removeClass('is-hidden'); |
||
62 | break; |
||
63 | case 'available': |
||
64 | $('#swMessageWhoisResults').text(domainResults); |
||
65 | $('#swMessageAvailable').removeClass('is-hidden'); |
||
66 | break; |
||
67 | default: |
||
68 | $('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults)); |
||
69 | $('#swMessageError').removeClass('is-hidden'); |
||
70 | break; |
||
71 | } |
||
72 | |||
73 | $('#swSearchButtonSearch').removeClass('is-loading'); |
||
74 | $('#swSearchInputDomain').removeAttr('readonly'); |
||
75 | |||
76 | }); |
||
77 | |||
133 |